import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { Article } from './article.entity';

@Entity()
export class DocumentChunk {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ comment: '文档分块内容' })
  content: string;

  @Column({ comment: '向量化数据', type: 'json' })
  embedding: number[];

  @Column({ comment: '分块索引' })
  chunkIndex: number;

  @Column({ comment: '分块大小' })
  chunkSize: number;

  @Column({ comment: '元数据', type: 'json', nullable: true })
  metadata: Record<string, any>;

  @ManyToOne(() => Article, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'articleId' })
  article: Article;

  @Column({ comment: '关联的文章ID' })
  articleId: number;

  @CreateDateColumn({ comment: '创建时间' })
  createdAt: Date;
} 